package org.example.neusoft.view;

import org.example.neusoft.dao.ArticleDao;
import org.example.neusoft.model.Article;
import org.example.neusoft.model.User;
import org.example.neusoft.util.GlobalInput;

import java.text.SimpleDateFormat;
import java.util.*;

public class ArticleView {
    public void createArticle() {
        Article article = new Article();
        Scanner scanner = GlobalInput.getScanner();
        System.out.println("请输入标题");
        article.setTitle(scanner.nextLine());
        System.out.println("请输入内容");
        article.setBody(scanner.nextLine());
        System.out.println("请输入文章标签");
        article.setTags(scanner.nextLine());
        article.setId(UUID.randomUUID().toString());
        article.setUser_id(User.loginUser.getId());
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String strDate = sdf.format(date);
        article.setCreated_at(strDate);
        article.setUpdated_at(strDate);
        ArticleDao articleDao = new ArticleDao();
        articleDao.createArticle(article);
    }

    public List<Map<String, String>> getAllArticleLst() {
        ArticleDao articleDao = new ArticleDao();
        return articleDao.getAllArticleLst();
    }

    public void takeFavorite(String article_id, String user_id) {
        ArticleDao articleDao = new ArticleDao();
        articleDao.takeFavorite(article_id, user_id);
    }

    public void takeCommand(String content, String article_id, String user_id) {
        ArticleDao articleDao = new ArticleDao();
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String strDate = sdf.format(date);
        String created_at = strDate;
        String updated_at = strDate;
        articleDao.takeCommand(content, article_id, user_id, created_at, updated_at);
    }
}
